package com.health.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.health.system.annotation.Log;
import com.health.system.common.result.Result;
import com.health.system.entity.HealthLog;
import com.health.system.service.LogService;
import com.health.system.vo.LogListPageSearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.health.system.constant.LogTypeConstant.SELECT;


@Validated
@Api(tags = "日志管理")
@RestController
public class HealthLogController {
    @Autowired
    private LogService operationLogService;

    @Log(SELECT)
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "current", value = "当前页", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "size", value = "每页显示数量", dataTypeClass = Long.class)
            }
    )
    @ApiOperation(value = "操作日志分页列表")
    @GetMapping("/admin/operation/listPage")
    public Result<IPage<HealthLog>> operationListPage(@RequestParam(value = "current", defaultValue = "1") Long current,
                                                      @RequestParam(value = "size", defaultValue = "10") Long size,
                                                      LogListPageSearchVo condition) {
        IPage<HealthLog> result = operationLogService.selectInfoListPage(current, size, condition);
        return Result.ok(result);
    }

    @Log(SELECT)
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "current", value = "当前页", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "size", value = "每页显示数量", dataTypeClass = Long.class)
            }
    )
    @ApiOperation(value = "异常日志分页列表")
    @GetMapping("/admin/error/listPage")
    public Result<IPage<HealthLog>> errorListPage(@RequestParam(value = "current", defaultValue = "1") Long current,
                                                @RequestParam(value = "size", defaultValue = "10") Long size,
                                                LogListPageSearchVo condition) {
        IPage<HealthLog> result = operationLogService.selectErrorListPage(current, size, condition);
        return Result.ok(result);

    }
}
